package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbcConnection {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 1. 导入驱动jar包
        // 2. 注册驱动
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        // Class.forName("org.gjt.mm.mysql.Driver");
        // 3. 获取数据库的连接对象
        Connection conn = DriverManager.getConnection("jdbc:sqlserver://192.168.227.56:1433", "sa", "123qwe");

        // 4. 定义SQL语句
        String sql = "update students set name = '苍井空' where id = 4";
        // 5. 获取执行sql 的对象 Statement
        Statement stmt = conn.createStatement();
        // 6. 执行 sql
       // conn.open();
        int count = stmt.executeUpdate(sql);
        // 7. 处理结果
        System.out.println(count);
        // 8. 释放资源
        stmt.close();
        conn.close();
    }
}
